﻿using NeonLampTest.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NeonLampTest
{
    public class NeonLamp : Control
    {
        private readonly System.Timers.Timer _timer;
        private readonly SurroundList _sl;
        public NeonLamp()
        {
            SetStyle(
         ControlStyles.ResizeRedraw
         | ControlStyles.DoubleBuffer
         | ControlStyles.UserPaint
         | ControlStyles.AllPaintingInWmPaint
         | ControlStyles.SupportsTransparentBackColor,
         true
         );
            this.BackColor = Color.Black;
            _sl= new SurroundList();
            _timer = new System.Timers.Timer();
            _timer.Interval = 50;
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
        }
        private void _timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
        {
            lock (this)
            {
                _sl.Change();
                this.Invalidate();
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.Smooth();
            _sl.Draw(g);
            g.Smooth(false);

        }
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            _sl.SizeChange(this.Width, this.Height);
        }
    }
}
